package com.oracle.lingshangejia.activity.special;

import android.app.DatePickerDialog;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.oracle.lingshangejia.Constant;
import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.adapter.special.CJArchivesExtendableListAdapter;
import com.oracle.lingshangejia.bean.DataBean;
import com.oracle.lingshangejia.bean.HubbyBean;
import com.oracle.lingshangejia.bean.User;
import com.oracle.lingshangejia.dialog.LoadingViewDialog;
import com.oracle.lingshangejia.model.OkgoNetwork;
import com.oracle.lingshangejia.utils.MyLogger;
import com.oracle.lingshangejia.utils.MyToast;
import com.oracle.lingshangejia.utils.ObserverOnNext;
import com.oracle.lingshangejia.utils.RxUtils;

import org.json.JSONObject;

import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;

//孕产妇一次产前检查记录
public class ChanjianArchivesActivity extends AppCompatActivity {
    private ExpandableListView expandableListView;
    private CJArchivesExtendableListAdapter archivesExtendableListAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cj_add_archives_activity);
        initBasic();

        expandableListView = findViewById(R.id.expend_list);
        String[] archivesStr = getResources().getStringArray(R.array.chan_jian_archives);
        archivesExtendableListAdapter = new CJArchivesExtendableListAdapter(archivesStr);
        expandableListView.setAdapter(archivesExtendableListAdapter);
        // 添加末尾提交按钮
        View foot = LayoutInflater.from(this).inflate(R.layout.archives_foot_submit, null);
        expandableListView.addFooterView(foot);

        expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                return false;
            }
        });

        expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
            @Override
            public void onGroupExpand(int groupPosition) {
                int count = expandableListView.getExpandableListAdapter().getGroupCount();
                for (int i = 0; i < count; i++) {
                    if (i != groupPosition) {
                        expandableListView.collapseGroup(i);
                    }
                }
            }
        });
        expandableListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
            @Override
            public void onGroupCollapse(int groupPosition) {
                View[] views = ((CJArchivesExtendableListAdapter) expandableListView.getExpandableListAdapter()).getConvertViews();
                View view = views[groupPosition];
                if (view == null) {
                    return;
                }
                Map<String, String> values = null;
                switch (groupPosition) {
                    case 0:
                        values = getBasicInfoValues();
                        break;
                    case 1:
                        values = getEducationAndProfessionalAndMarriageAndPayValues(view);
                        break;
                    case 2:
                        values = getAllergyAndExposedValues(view);
                        break;
                    case 3:
                        values = getDiseaseValues(view);
                        break;
                    case 4:
                        values = getSurgeryAndTraumaAndTransfusionValues(view);
                        break;
                    case 5://6
                        values = getGeneticDiseaseAndDisabilityAndEnvironmentValues(view);
                        break;
                    case 6:
                        values = healthyNewborn(view);
                        break;
                    case 7:
                        values = physicalExaminationOfNewbornSurgery(view);
                        break;
                    case 8:
                        values = adviceAndGuidance(view);
                        break;
                    case 9://11
                        values = getFamilialDiseaseFatherValues(view);
                        break;
                    case 10://13
                        values = getFamilialDiseaseBrotherValues(view);
                        break;
                }


            }
        });

        expandableListView.expandGroup(0);

    }


    /**
     * 检查用户名、身份证号和本人联系电话是否正确填写
     *
     * @return 数据不正确返回true，正确返回false
     */
    private boolean checkBasicInfoIsError() {
        Map<String, String> basicInforValues = getBasicInfoValues();
        String xm = (String) basicInforValues.get("xm");
        // 姓名非空验证
        if (xm == null || xm.length() == 0) {
            Toast.makeText(getApplicationContext(), "姓名必须填写", Toast.LENGTH_SHORT).show();
            return true;
        }
        return false;
    }



    /**
     * 获取基本信息数据
     * 第一页
     */
    private Map<String, String> getBasicInfoValues() {
        View[] views = ((CJArchivesExtendableListAdapter) expandableListView.getExpandableListAdapter()).getConvertViews();
        View view = views[0];
        Map<String, String> params = new HashMap<>();
        /*
         * 第一页，基本信息1
         */
        // 姓名
        String username = "";
        // 填表日期
        String date = "";
        // 孕周
        String gestationalweek = "";
        // 孕妇年龄
        String maternalage = "";
        //居民id
        String residentID="";
        //医生id
        String doctorID="";
        //产次
        String Parity="";

      //  username = ((EditText) view.findViewById(R.id.antenatal_username)).getText().toString().trim();
       // date = ((TextView) view.findViewById(R.id.antenatal_date)).getText().toString().trim();
        gestationalweek = ((EditText) view.findViewById(R.id.antenatal_gestationalweek)).getText().toString().trim();
        maternalage = ((EditText) view.findViewById(R.id.antenatal_maternalage)).getText().toString().trim();
       // residentID = ((EditText) view.findViewById(R.id.antenatal_resident_id)).getText().toString().trim();
      //  doctorID = ((EditText) view.findViewById(R.id.antenatal_doctor_id)).getText().toString().trim();
        Parity = ((EditText) view.findViewById(R.id.antenatal_Parity)).getText().toString().trim();

      //  params.put("xm", username);
     // params.put("date", date);//填表日期
        params.put("yz", gestationalweek);//	//孕周
        params.put("yfnl", maternalage);//年龄
       // params.put("grjbxx_id", residentID);//
       // params.put("create_by", doctorID);//
        params.put("cc", Parity);// 产次

        /*
         * 第二页，基本信息2
         */

        // 丈夫姓名
        String husbandname = "";
        // 丈夫年龄
        String husbandage = "";
        // 丈夫电话
        String husbandphone = "";
        // 孕次
        String gravidity = "";
        // 阴道分娩
        String vaginaldelivery = "";
        // 剖宫产
        String cesareansection = "";
        // 末次月经
        String lastmenstrualperiod = "";
        // 预产期
        String expecteddateofchildbirth = "";


        if (mBean != null && mBean.getData()!=null){
            ((EditText) view.findViewById(R.id.antenatal_husbandname)).setText(mBean.getData().getZfxm());
            ((EditText) view.findViewById(R.id.antenatal_husbandage)).setText(mBean.getData().getZfnl()+"");
            ((EditText) view.findViewById(R.id.antenatal_husbandphone)).setText(mBean.getData().getZfdh());
        }

        husbandname = ((EditText) view.findViewById(R.id.antenatal_husbandname)).getText().toString().trim();
        husbandage = ((EditText) view.findViewById(R.id.antenatal_husbandage)).getText().toString().trim();
        husbandphone = ((EditText) view.findViewById(R.id.antenatal_husbandphone)).getText().toString().trim();
        gravidity = ((EditText) view.findViewById(R.id.antenatal_gravidity)).getText().toString().trim();
        vaginaldelivery = ((EditText) view.findViewById(R.id.antenatal_vaginaldelivery)).getText().toString().trim();
        cesareansection = ((EditText) view.findViewById(R.id.antenatal_lastmenstrualperiod)).getText().toString().trim();
        if (((CheckBox) view.findViewById(R.id.antenatal_expecteddateofchildbirth_2)).isChecked()) {
            lastmenstrualperiod = "不详";
        } else {
            lastmenstrualperiod = ((TextView) view.findViewById(R.id.antenatal_expecteddateofchildbirth_1)).getText().toString().trim();
        }
        expecteddateofchildbirth = ((TextView) view.findViewById(R.id.antenatal_expecteddateofchildbirth)).getText().toString().trim();
        params.put("zfxm", husbandname); //姓名
        params.put("zfnl", husbandage);   //年龄
        params.put("zfdh", husbandphone);  //电话
        params.put("yc", gravidity);//孕次
        params.put("ydfm", vaginaldelivery);//阴道分娩次
        params.put("pgc", cesareansection);//刨宫产次
        params.put("mcyjsj", lastmenstrualperiod);//末经
        params.put("ycq", expecteddateofchildbirth);//预产期
        mValues.putAll(params);
        return params;
    }

    /**
     * 既往史/家族史/个人史
     * 第二页
     */
    private Map<String, String> getEducationAndProfessionalAndMarriageAndPayValues(View view) {
        Map<String, String> params = new HashMap<>();
        String PastHistory = "";
        String PastHistoryOther = "";
        if (view != null) {
            View[] PastHistoryFatherViews= getViews(view.findViewById(R.id.tl_jws));
            for (int i = 0; i < PastHistoryFatherViews.length; i++) {
                if (PastHistoryFatherViews[i] instanceof CheckBox) {
                    CheckBox cb = (CheckBox) PastHistoryFatherViews[i];
                    if (cb.isChecked()) {
                        String s = cb.getText().toString().trim();
                        s = s.substring(0, s.indexOf(" "));
                        PastHistory += s;
                        PastHistory += ",";
                    }
                }
            }
            if (PastHistory.length() != 0) {
                PastHistory = PastHistory.substring(0, PastHistory.length() - 1);
            }
            PastHistoryOther = ((EditText) view.findViewById(R.id.antenatal_PastHistory_8_text)).getText().toString().trim();
        }
        params.put("jws", PastHistory); //既往史
        params.put("jwsQt", PastHistoryOther);//其他

        /*
         * 第四页，家族史
         */
        String FamilyHistory = "";
        String FamilyHistoryOther = "";
        if (view!= null) {
            View[] cbs = getViews(view.findViewById(R.id.tl_jzs));
            for (int i = 0; i < cbs.length; i++) {
                if (cbs[i] instanceof CheckBox) {
                    CheckBox cb = (CheckBox) cbs[i];
                    if (cb.isChecked() /*&& cb.getId() != R.id.antenatal_FamilyHistory_4*/) {
                        String s = cb.getText().toString().trim();
                        s = s.substring(0, s.indexOf(" "));
                        FamilyHistory += s;
                        FamilyHistory += ",";
                    }
                }
            }
            if (FamilyHistory.length() != 0) {
                FamilyHistory= FamilyHistory.substring(0, FamilyHistory.length() - 1);
            }
            FamilyHistoryOther = ((EditText) view.findViewById(R.id.antenatal_FamilyHistory_4_text)).getText().toString().trim();
        }
        params.put("jzs", FamilyHistory);///家族
        params.put("jzsQt", FamilyHistoryOther);//其他



        /*
         *第五页，个人史
         */
        String Personalhistory = "";
        String Personalhistoryother = "";
        if (view != null) {
            View[] cbs = getViews(view.findViewById(R.id.tl_grs));
            for (int i = 0; i < cbs.length; i++) {
                if (cbs[i] instanceof CheckBox) {
                    CheckBox cb = (CheckBox) cbs[i];
                    if (cb.isChecked() /*&& cb.getId() != R.id.antenatal_Symptom_other*/) {
                        String s = cb.getText().toString().trim();
                        s = s.substring(0, s.indexOf(" "));
                        Personalhistory += s;
                        Personalhistory += ",";
                    }
                }
            }
            if (Personalhistory.length() != 0) {
                Personalhistory = Personalhistory.substring(0, Personalhistory.length() - 1);
            }
            Personalhistoryother = ((EditText) view.findViewById(R.id.antenatal_Symptom_text)).getText().toString().trim();
        }
        params.put("grs", Personalhistory);//个人
        params.put("grsQt", Personalhistoryother);//其他
        mValues.putAll(params);
        MyLogger.i((new JSONObject(params).toString()));
        return params;
    }

    /**
     * 妇产科手术史
     * 第三页
     */
    private Map<String, String> getAllergyAndExposedValues(View view) {
        Map<String, String> params = new HashMap<>();
        String naturalabortion = "";
        // 人工流产
        String inducedabortion = "";
        // 死胎
        String deadfetus = "";
        // 死产
        String deadbirth = "";
        // 新生儿死亡
        String Neonataldeath= "";
        // chushengquexianer

        String Birthdefect = "";
        //
        String Shoushu = "";

        String HistoryfoGynecological = "";

        naturalabortion = ((EditText) view.findViewById(R.id.antenatal_naturalabortion)).getText().toString().trim();
        inducedabortion = ((EditText) view.findViewById(R.id.antenatal_inducedabortion)).getText().toString().trim();
        deadfetus = ((EditText) view.findViewById(R.id.antenatal_deadfetus)).getText().toString().trim();
        deadbirth = ((EditText) view.findViewById(R.id.antenatal_deadbirth)).getText().toString().trim();
        Neonataldeath = ((EditText) view.findViewById(R.id.antenatal_Neonataldeath)).getText().toString().trim();
        Birthdefect = ((EditText) view.findViewById(R.id.antenatal_Birthdefect)).getText().toString().trim();
        //gender = ((Spinner) view.findViewById(R.id.archives_gender)).getSelectedItem().toString().trim();
        // gender = gender.substring(0, gender.indexOf(" "));
        String genetic = "";
        String geneticName = "";
        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_HistoryfoGynecological);
            RadioButton all = view.findViewById(R.id.antenatal_HistoryfoGynecological_1);
            if (none.isChecked()) {
                genetic = "1";
            } else {
                genetic = "2";
            }
            Shoushu = ((EditText) view.findViewById(R.id.antenatal_fuchankeshoushushi_other)).getText().toString().trim();
        }
        params.put("fcksss", genetic);  //妇产科手术
        params.put("fcksssMz", Shoushu);//妇产科手术名字    新


        params.put("zrlcCs", naturalabortion);//自然流产次数     新
        params.put("rglcCs", inducedabortion);//人工流产次数       新
        params.put("sdCs", deadfetus);//死胎次数             新
        params.put("scCs", deadbirth);//死产次数                  新
        params.put("xseswCs", Neonataldeath);//新生儿死亡       新
        params.put("csqxeCs", Birthdefect);//出生缺陷           新
       mValues.putAll(params);
        MyLogger.i((new JSONObject(params).toString()));
        return params;

    }
    /**
     * 身高/体重/体质指数/血压
     * 第四页
     */
    private Map<String, String> getDiseaseValues(View view) {
        Map<String, String> params = new HashMap<>();
         /*
            第四页 身高/体重/体质指数/血压
         */
        // 身高
        String shengao = "";
        // 体重
        String tizhong = "";
        // 体质指数
        String tizhizhishu = "";
        // 血压
        String xueya = "";
        // 血压
        String xueya_2 = "";

        shengao = ((EditText) view .findViewById(R.id.antenatal_shengao1)).getText().toString().trim();
        tizhong = ((EditText) view .findViewById(R.id.antenatal_shengao2)).getText().toString().trim();
        tizhizhishu = ((EditText) view .findViewById(R.id.antenatal_shengao3)).getText().toString().trim();
        xueya = ((EditText) view .findViewById(R.id.antenatal_shengao4)).getText().toString().trim();
        xueya_2 = ((EditText) view .findViewById(R.id.antenatal_shengao5)).getText().toString().trim();


        params.put("ycfSg", shengao);//身高
        params.put("ycfTz", tizhong);//体重
        params.put("ycfTzzs", tizhizhishu);// 体质
        params.put("ycfXySsl", xueya);///血压收缩
        params.put("ycfXySzl", xueya_2);///舒张

          /*
            第八页 妇产科手术史
         */
        // 自然流产

        String xinzang = "";
        String xinzang_yc = "";
        // 人工流产
        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_xzwyc);
            RadioButton all = view.findViewById(R.id.antenatal_xzwyc_1);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                xinzang  = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                xinzang  = s;
            }
            xinzang_yc = ((EditText) view.findViewById(R.id.antenatal_xzycother)).getText().toString().trim();
        }
        String feibu = "";
        String feibu_yc = "";
        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_fbwyc);
            RadioButton all = view.findViewById(R.id.antenatal_fbwyc_1);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                feibu  = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                feibu  = s;
            }
            feibu_yc = ((EditText) view .findViewById(R.id.antenatal_fbycother)).getText().toString().trim();
        }
        params.put("ycfTzXz", xinzang);//心脏
        params.put("ycfTzXzDesc", xinzang_yc);//其他
        params.put("ycfTzFb", feibu);//肺部
        params.put("ycfTzFbDesc", feibu_yc);//其他

       mValues.putAll(params);
        return params;
    }

    /**
     * 第五页 妇科检查
     */
    private Map<String, String> getSurgeryAndTraumaAndTransfusionValues(View view) {
        Map<String, String> params = new HashMap<>();
          /*
            第无页 妇科检查
         */
        // 外阴
        String waiyin = "";
        // 阴道
        String yindao = "";
        // 宫颈
        String gongjing = "";
        // 子宫
        String zigong = "";
        // 附件
        String fujian = "";
        // 外阴
        String waiyin_yc = "";
        // 阴道
        String yindao_yc= "";
        // 宫颈
        String gongjing_yc = "";
        // 子宫
        String zigong_yc = "";
        // 附件
        String fujian_yc = "";
        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_fukejiancha_waiyin_noyichang);
            RadioButton all = view.findViewById(R.id.antenatal_fukejiancha_waiyin_noyichang_1);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                waiyin  = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                waiyin  = s;
            }
            waiyin_yc = ((EditText) view .findViewById(R.id.antenatal_fukejiancha_waiyin_other_text)).getText().toString().trim();
        }

        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_fukejiancha_yindao_noyichang);
            RadioButton all = view.findViewById(R.id.antenatal_fukejiancha_yindao_noyichang_1);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                yindao  = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                yindao  = s;
            }
            yindao_yc = ((EditText) view .findViewById(R.id.antenatal_fukejiancha_yindao_other_txt)).getText().toString().trim();
        }

        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_gongjingyichang);
            RadioButton all = view.findViewById(R.id.antenatal_gongjingyichang_1);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                gongjing  = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                gongjing  = s;
            }
            gongjing_yc = ((EditText) view .findViewById(R.id.antenatal_gongjingyichang2)).getText().toString().trim();
        }

        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_zigongyichang);
            RadioButton all = view.findViewById(R.id.antenatal_zigongyichang_1);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                zigong  = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                zigong  = s;
            }
            zigong_yc = ((EditText) view .findViewById(R.id.antenatal_zigongyichangother)).getText().toString().trim();
        }

        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_fujian);
            RadioButton all = view.findViewById(R.id.antenatal_fujian_1);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                fujian  = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                fujian  = s;
            }
            fujian_yc = ((EditText) view .findViewById(R.id.antenatal_fujianyichangother)).getText().toString().trim();
        }
//        waiyin_yc = ((EditText) view .findViewById(R.id.antenatal_fukejiancha_waiyin_other_text)).getText().toString().trim();
//        yindao_yc = ((EditText) view .findViewById(R.id.antenatal_fukejiancha_yindao_other_txt)).getText().toString().trim();
//        gongjing_yc = ((EditText) view .findViewById(R.id.antenatal_gongjingyichang2)).getText().toString().trim();
//        zigong_yc = ((EditText) view .findViewById(R.id.antenatal_zigongyichangother)).getText().toString().trim();
//        fujian_yc = ((EditText) view .findViewById(R.id.antenatal_fujianyichangother)).getText().toString().trim();

        params.put("ycfFkjcWy", waiyin);//外阴
        params.put("ycfFkjcYd", yindao);///阴道
        params.put("ycfFkjcGj", gongjing);//宫颈
        params.put("ycfFkjcZg", zigong );//子宫
        params.put("ycfFkjcFj", fujian);//附件
         //异常详情
        params.put("ycfFkjcWyDesc", waiyin_yc);//
        params.put("ycfFkjcYdDesc", yindao_yc);//
        params.put("ycfFkjcGjDesc", gongjing_yc);//
        params.put("ycfFkjcZgDesc", zigong_yc );//
        params.put("ycfFkjcFjDesc", fujian_yc);//

         mValues.putAll(params);
        return params;
    }



    /*
     * 第6页，血红蛋白值
     */
    private Map<String, String> getGeneticDiseaseAndDisabilityAndEnvironmentValues(View view) {
        Map<String, String> params = new HashMap<>();
        /*
         * 第X页，血红蛋白值
         */
        // 血红蛋白值
        String Hemoglobin = "";
        // 白细胞计数值
        String Whiteblood = "";
        // 血小板计数值
        String Platelet = "";
        // 其他
        String Other1 = "";
        // 尿蛋白
        String Urineprotein = "";
        // 尿糖
        String Urinesugar = "";
        // 尿酮体
        String Ketonebodies = "";
        // 尿潜血
        String Bld = "";
        // 其他2
        String Other2 = "";

        Hemoglobin = ((EditText) view.findViewById(R.id.antenatal_et_1)).getText().toString().trim();
        Whiteblood = ((EditText) view.findViewById(R.id.antenatal_et_2)).getText().toString().trim();
        Platelet = ((TextView) view.findViewById(R.id.antenatal_et_3)).getText().toString().trim();
        Other1 = ((EditText) view.findViewById(R.id.antenatal_et_5)).getText().toString().trim();
        Urineprotein = ((EditText) view.findViewById(R.id.antenatal_et_6)).getText().toString().trim();
        Urinesugar = ((EditText) view.findViewById(R.id.antenatal_et_7)).getText().toString().trim();
        Ketonebodies = ((EditText) view.findViewById(R.id.antenatal_et_8)).getText().toString().trim();
        Bld = ((EditText) view.findViewById(R.id.antenatal_et_9)).getText().toString().trim();
        Other2 = ((EditText) view.findViewById(R.id.antenatal_et_4)).getText().toString().trim();

        params.put("fzjcXcgXgdb", Hemoglobin);////红蛋白
        params.put("fzjcXcgBxb", Whiteblood);//白细胞
        params.put("fzjcXcgXxbjs", Platelet);///血小板
        params.put("fzjcXcgQt", Other1);///   其他
        params.put("fzjcNcgNdb", Urineprotein);///尿蛋白
        params.put("fzjcNcgTnb", Urinesugar);//尿糖
        params.put("fzjcNcgTtn", Ketonebodies);///酮体
        params.put("fzjcNcgQx", Bld);//潜血
        params.put("fzjcNcgQt", Other2);///其他
         mValues.putAll(params);
        return params;
    }
    /*
     * 第7页，血型-血尿素
     */
    private Map<String, String> healthyNewborn(View view) {
        Map<String, String> params = new HashMap<>();
        /*
         * 第X页，血型-血尿素
         */
        // 血型
        String Bloodtype = "";
        // Rh型
        String Rh = "";
        // 血糖
        String Bloodsugar = "";
        // 血清谷丙转氨酶
        String Serumalanine = "";
        // 血清谷草转氨酶
        String Serumglutamic = "";
        // 白蛋白
        String Albumin = "";
        // 总胆红素
        String Totalbilirubin = "";
        // 结合胆红素
        String Bindingbilirubin = "";
        // 血清肌酐
        String Scr = "";
        // 血尿素
        String Bloodurea = "";
        Bloodtype = ((Spinner) view.findViewById(R.id.antenatal_xuexing)).getSelectedItem().toString().trim();
        Bloodtype = Bloodtype.substring(0, Bloodtype.indexOf(" "));
        Rh = ((Spinner) view.findViewById(R.id.antenatal_RH)).getSelectedItem().toString().trim();
        Rh = Rh.substring(0, Rh.indexOf(" "));
        Bloodsugar = ((EditText) view.findViewById(R.id.antenatal_xue1)).getText().toString().trim();
        Serumalanine = ((EditText) view.findViewById(R.id.antenatal_xue2)).getText().toString().trim();
        Serumglutamic = ((TextView) view.findViewById(R.id.antenatal_xue3)).getText().toString().trim();
        Albumin = ((EditText) view.findViewById(R.id.antenatal_xue4)).getText().toString().trim();
        Totalbilirubin = ((EditText) view.findViewById(R.id.antenatal_xue5)).getText().toString().trim();
        Bindingbilirubin = ((EditText) view.findViewById(R.id.antenatal_xue6)).getText().toString().trim();
        Scr = ((EditText) view.findViewById(R.id.antenatal_xue7)).getText().toString().trim();
        Bloodurea = ((EditText) view.findViewById(R.id.antenatal_xue8)).getText().toString().trim();

        params.put("fzjcXxAbo", Bloodtype);//血型
        params.put("fzjcXxRh", Rh);//RH
        params.put("fzjcXt", Bloodsugar);//血糖
        params.put("fzjcGgnXqgbzam", Serumalanine);//// 血清谷丙转氨酶
        params.put("fzjcGgnXqgczam", Serumglutamic);//   // 血清谷草转氨酶
        params.put("fzjcGgnBdb", Albumin);///白蛋白
        params.put("fzjcGgnZdhs", Totalbilirubin);///总胆红素
        params.put("fzjcGgnJhdhs", Bindingbilirubin);///结合胆红
        params.put("fzjcGgnSr", Scr);//血清肌
        params.put("fzjcGgnBu", Bloodurea);//血尿素
        mValues.putAll(params);
        return  params;
    };
    /*
     * 第8页，阴道分泌物
     */
    private Map<String, String> physicalExaminationOfNewbornSurgery(View view) {
        Map<String, String> params = new HashMap<>();

        /*
         * 第8页，阴道分泌物
         */
        String fenmiwu = "";
        String fenmiwuQita = "";

        TableLayout table = ((TableLayout) view.findViewById(R.id.antenatal_fenmiwu));
        View[] cbs = getViews(table);
        for (int i = 0; i < cbs.length; i++) {
            if (cbs[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) cbs[i];
                if (cb.isChecked() && cb.getId() != R.id.antenatal_cb_5) {
                    String s = cb.getText().toString().trim();
                    s = s.substring(0, s.indexOf(" "));
                    fenmiwu += s;
                    fenmiwu += ",";
                }
            }
        }
        if (fenmiwu.length() != 0) {
            fenmiwu = fenmiwu.substring(0, fenmiwu.length() - 1);
        }
        fenmiwuQita = ((EditText) view.findViewById(R.id.antenatal_pay_other_text)).getText().toString().trim();

        params.put("fzjcYdfmw", fenmiwu);////阴道分泌物
        params.put("fzjcYdfmwQt", fenmiwuQita);//其他
//阴道清洁度
        String yindao = "";
        if (((RadioButton) view.findViewById(R.id.antenatal_fuchankeshoushushi)).isChecked()) {
            //national = "1 汉族";
            yindao = "1";
        } else if (((RadioButton) view.findViewById(R.id.antenatal_fuchankeshoushushi_1)).isChecked()){
            //national = ((EditText) views[0].findViewById(R.id.archives_national_other)).getText().toString().trim();
            yindao = "2";
        } else if (((RadioButton) view.findViewById(R.id.antenatal_fuchankeshoushushi_2)).isChecked()){
            //national = ((EditText) views[0].findViewById(R.id.archives_national_other)).getText().toString().trim();
            yindao = "3";
        }else if (((RadioButton) view.findViewById(R.id.antenatal_fuchankeshoushushi_3)).isChecked()){
            //national = ((EditText) views[0].findViewById(R.id.archives_national_other)).getText().toString().trim();
            yindao = "4";
        }
        params.put("fzjcYdqjd", yindao);//阴道情洁°
        mValues.putAll(params);

        return params;
    };

    private Map<String, String> adviceAndGuidance(View view) {
        Map<String, String> params = new HashMap<>();
        /*
         * 第X页，血红蛋白值
         */
        // 乙型肝炎表面抗原
        String Surfaceantibody_1 = "";
        // 乙型肝炎表面抗体
        String Surfaceantibody = "";
        // 乙型肝炎e抗原
        String Eantigen = "";
        // 乙型肝炎e抗体
        String Eantibody = "";
        // 乙型肝炎核心抗体
        String Coreantibody = "";

        Surfaceantibody_1= ((EditText) view.findViewById(R.id.antenatal_yigan)).getText().toString().trim();
        Surfaceantibody = ((EditText) view.findViewById(R.id.antenatal_yigan1)).getText().toString().trim();
        Eantigen= ((EditText) view.findViewById(R.id.antenatal_yigan3)).getText().toString().trim();
        Eantibody = ((TextView) view.findViewById(R.id.antenatal_yigan4)).getText().toString().trim();
        Coreantibody = ((EditText) view.findViewById(R.id.antenatal_yigan5)).getText().toString().trim();
        params.put("fzjcYxgyBmky", Surfaceantibody_1);// // 乙型肝炎表面抗原
        params.put("fzjcYxgyBmkt", Surfaceantibody);    // 乙型肝炎表面抗体
        params.put("fzjcYxgyEky", Eantigen);    // 乙型肝炎e抗原
        params.put("fzjcYxgyEkt", Eantibody);   // 乙型肝炎e抗体
        params.put("fzjcYxgyHxkt", Coreantibody);  // 乙型肝炎核心抗体

        /*
         * 第十一页，梅毒血清试验、HIV抗体检测、B超、其他
         */
        //梅毒血清试验
        String Cantanitest="";
        //HIV抗体检测
        String HIVAb="";
        // B超
        String typeB = "";
        // 其他
        String other= "";

        typeB = ((TextView) view.findViewById(R.id.antenatal_type_B_ultrasonic)).getText().toString().trim();
        other = ((EditText) view.findViewById(R.id.antenatal_other)).getText().toString().trim();
        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_Cantanitest_feminine);
            RadioButton all = view.findViewById(R.id.antenatal_Cantanitest_feminine_1);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                Cantanitest  = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                Cantanitest  = s;
            }
//            Cantanitest_yc = ((EditText) view .findViewById(R.id.antenatal_fukejiancha_yindao_other_txt)).getText().toString().trim();
        }

        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_HIVAb_feminine);
            RadioButton all = view.findViewById(R.id.antenatal_HIVAb_feminine_1);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                HIVAb  = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                HIVAb  = s;
            }
//            HIVAb_yc = ((EditText) view .findViewById(R.id.antenatal_fukejiancha_yindao_other_txt)).getText().toString().trim();
        }

        params.put( "fzjcMdxqxsy", Cantanitest ); //梅毒血清试验
        params.put( "fzjcKtjc", HIVAb );  //HIV抗体检测
        params.put( "fzjcYxgyBc", typeB );     // B超
        params.put( "fzjcYxgyQt", other );//qita
        mValues.putAll(params);
        return params;
    };
    /*
     * 第十一页，基本信息
     */
    //总体评估
    private Map<String, String> getFamilialDiseaseFatherValues(View view) {
        Map<String, String> params = new HashMap<>();
        String OverallAbility = "";

        String OverallAbility_other = "";
        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_OverallAbility_noAbnormalities);
            RadioButton all = view.findViewById(R.id.antenatal_OverallAbility_noAbnormalities_1);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                OverallAbility   = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                OverallAbility   = s;
            }
            OverallAbility_other = ((EditText) view .findViewById(R.id.antenatal_OverallAbility_Abnormalities_Text)).getText().toString().trim();
        }
        params.put("ztpg", OverallAbility );//总体评估（1-未见异常，2-异常）
        params.put("ztpgYc", OverallAbility_other);//异常内容
        /*
         * 第十三页，保健指导
         */
        // 保健指导
        String HealthGuidance = "";
        // 保健指导其它
        String otherHealthGuidance = "";

        View[] HealthGuidanceViews = getViews(view.findViewById(R.id.antenatal_HealthGuidance));
        for (int i = 0; i < HealthGuidanceViews.length; i++) {
            if (HealthGuidanceViews[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) HealthGuidanceViews[i];
                if (cb.isChecked() && cb.getId() != R.id.antenatal_HealthGuidance_lifeway_other) {
                    String s = cb.getText().toString().trim();
                    s = s.substring(0, s.indexOf(" "));
                    HealthGuidance += s;
                    HealthGuidance += ",";
                }
            }
        }
        if (HealthGuidance.length() != 0) {
            HealthGuidance = HealthGuidance.substring(0, HealthGuidance.length() - 1);
        }
        otherHealthGuidance = ((EditText) view.findViewById(R.id.antenatal_HealthGuidance_lifeway_other_text)).getText().toString().trim();


        params.put("bjzd", HealthGuidance);//健康知道
        params.put("bjzdQt", otherHealthGuidance);//其他

         mValues.putAll(params);

        return params;
    }

    /*
     * 第十三页，转诊
     */
    //转诊
    private Map<String, String> getFamilialDiseaseBrotherValues(View view) {
        Map<String, String> params = new HashMap<>();
        /*
         * 第十四页，转诊
         */
        //转诊
        String TransferTreatment = "";
        //原因
        String TransferTreatment_reason = "";
        //机构
        String TransferTreatment_Institutional = "";
        //科室
        String TransferTreatment_Institutional_1 = "";
        if (view != null) {
            RadioButton none = view.findViewById(R.id.antenatal_TransferTreatment_no);
            RadioButton all = view.findViewById(R.id.antenatal_TransferTreatment);
            if (none.isChecked()) {
                String s = none.getText().toString().trim();
                s = s.substring(0, s.indexOf(" "));
                TransferTreatment   = s;
            } else {
                String s = all.getText().toString().trim();
                if (s.length() > 0)
                    s = s.substring(0, s.indexOf(" "));
                TransferTreatment   = s;
            }
            TransferTreatment_reason = ((EditText) view .findViewById(R.id.antenatal_TransferTreatment_yes_reason)).getText().toString().trim();
            TransferTreatment_Institutional=((EditText) view.findViewById(R.id.antenatal_TransferTreatment_yes_Institutional)).getText().toString().trim();
            TransferTreatment_Institutional_1=((EditText) view.findViewById(R.id.antenatal_TransferTreatment_yes_Institutional_1)).getText().toString().trim();

        }

        params.put( "zzjy", TransferTreatment );//转诊
        params.put( "zzyy", TransferTreatment_reason );//原因
        params.put( "zzjg", TransferTreatment_Institutional );//机构
        params.put( "zzks", TransferTreatment_Institutional_1 );//科室
        /*
         * 第十四页，下次随访日期、随访医生签名
         */
        // 下次随访日期
        String NextFollowupDate = "";
        // 随访医生签名
        String FollowupDoctorSignature= "";

        NextFollowupDate = ((TextView) view.findViewById(R.id.antenatal_NextFollowupDate)).getText().toString().trim();
        FollowupDoctorSignature = ((EditText) view.findViewById(R.id.antenatal_Follow_upDoctorSignature)).getText().toString().trim();
        params.put("scsfsj", NextFollowupDate);//下次随访
        params.put("sfysqm", FollowupDoctorSignature);//医生签名
        mValues.putAll(params);
        return params;
    }

    /**
     * Toolbar的事件---返回
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * 点击日期选择框弹出DatePickerDialog
     */
    private Calendar calendar;
    private DatePickerDialog dialog;

    public void onTimeViewClick(final View v) {
        calendar = Calendar.getInstance();
        dialog = new DatePickerDialog(ChanjianArchivesActivity.this,
                new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year,
                                          int monthOfYear, int dayOfMonth) {
                        TextView tv = (TextView) v;
                        String month;
                        String day;
                        if (monthOfYear <9){
                            month = "0"+(monthOfYear+1);
                        }else {
                            month = ""+(monthOfYear+1);
                        }
                        if (dayOfMonth <10){
                            day = "0"+dayOfMonth;
                        }else {
                            day = dayOfMonth + "";
                        }
                        tv.setText(year + "-" + month  + "-" + day);
                    }
                }, calendar.get(Calendar.YEAR), calendar
                .get(Calendar.MONTH), calendar
                .get(Calendar.DAY_OF_MONTH));
        dialog.show();
    }

    /*既往史*/
    public void onPastHistoryClick(View view) {
        View[] views = getViews(findViewById(R.id.antenatal_PastHistory ));
        CheckBox none = findViewById(R.id.antenatal_PastHistory_1);
        CheckBox other = findViewById(R.id.antenatal_PastHistory_8);
        EditText otherText = findViewById(R.id.antenatal_PastHistory_8_text);
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view == none) {
                    if (none.isChecked() && cb != view) {
                        cb.setChecked(false);
                        otherText.setText("");
                        otherText.setEnabled(false);
                    }
                } else {
                    CheckBox v = (CheckBox) view;
                    if (v.isChecked()) {
                        none.setChecked(false);
                    }
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
            otherText.setFocusable(true);
            otherText.setFocusableInTouchMode(true);
            otherText.requestFocus();
        } else {
            otherText.setEnabled(false);
            otherText.setText("");
        }
    }

    /*家族史*/
    public void onFamilyHistoryClick(View view) {
        CheckBox none = findViewById(R.id.antenatal_FamilyHistory_1);
        CheckBox other = findViewById(R.id.antenatal_FamilyHistory_4);
        EditText otherText = findViewById(R.id.antenatal_FamilyHistory_4_text);
        View[] views = getViews(findViewById(R.id.antenatal_PastHistory));
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view.getId() == R.id.antenatal_FamilyHistory_1 && cb.getId() != R.id.antenatal_FamilyHistory_1) {
                    if (none.isChecked()) {
                        cb.setChecked(false);
                        otherText.setText("");
                        otherText.setEnabled(false);
                    }
                } else if (view.getId() != R.id.antenatal_FamilyHistory_1) {
                    if (cb.isChecked()) {
                        none.setChecked(false);
                    }
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
        } else {
            otherText.setText("");
            otherText.setEnabled(false);
        }
    }

    /**
     * 下次访问日期
     */

    public void onXiacisuifangriqiClick(final View v) {
        calendar = Calendar.getInstance();
        dialog = new DatePickerDialog(ChanjianArchivesActivity.this,
                new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year,
                                          int monthOfYear, int dayOfMonth) {
                        TextView tv = (TextView) v;
                        String month;
                        String day;
                        if (monthOfYear <9){
                            month = "0"+(monthOfYear+1);
                        }else {
                            month = ""+(monthOfYear+1);
                        }
                        if (dayOfMonth <10){
                            day = "0"+dayOfMonth;
                        }else {
                            day = dayOfMonth + "";
                        }
                        tv.setText(year + "-" + month  + "-" + day);
                    }
                }, calendar.get(Calendar.YEAR), calendar
                .get(Calendar.MONTH), calendar
                .get(Calendar.DAY_OF_MONTH));
        dialog.show();
    }

    /**
     * 总体评估
     */
    public void OverallAbility(View view) {
        EditText ed = findViewById(R.id.antenatal_OverallAbility_Abnormalities_Text);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.antenatal_OverallAbility_noAbnormalities) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
        }
    }

    /**
     * 保健指导
     */
    public void onBaojianzhidaoClick(View view) {
        CheckBox none = findViewById(R.id.antenatal_baojianzhidao_shenghuofangshi);
        CheckBox other = findViewById(R.id.antenatal_HealthGuidance_lifeway_other);
        EditText otherText = findViewById(R.id.antenatal_HealthGuidance_lifeway_other_text);
        View[] views = getViews(findViewById(R.id.antenatal_HealthGuidance));
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view.getId() == R.id.antenatal_baojianzhidao_shenghuofangshi && cb.getId() != R.id.antenatal_baojianzhidao_shenghuofangshi) {
                    if (none.isChecked()) {
                        cb.setChecked(false);
                        otherText.setText("");
                        otherText.setEnabled(false);
                    }
                }
            }
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
        } else {
            otherText.setText("");
            otherText.setEnabled(false);
        }
    }

    /**
     * 转诊
     */
    public void changeZhuanzhenEnableEdit(View view) {
        EditText ed1 = findViewById(R.id.antenatal_TransferTreatment_yes_reason);
        EditText ed2 = findViewById(R.id.antenatal_TransferTreatment_yes_Institutional);
        EditText ed3 = findViewById(R.id.antenatal_TransferTreatment_yes_Institutional_1);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.antenatal_TransferTreatment_no) {
            ed1.setText("");
            ed1.setEnabled(false);
            ed2.setText("");
            ed2.setEnabled(false);
            ed3.setText("");
            ed3.setEnabled(false);
        } else if (rb.isChecked()) {
            ed1.setEnabled(true);
            ed2.setEnabled(true);
            ed3.setEnabled(true);
        }
    }
    /*个人史*/
    public void onAllergyClick(View view) {
        View[] views = getViews(findViewById(R.id.antenatal_PastHistory));
        CheckBox none = findViewById(R.id.antenatal_Personalhistory_un_specificness);
        CheckBox other = findViewById(R.id.antenatal_Symptom_other);
        EditText otherText = findViewById(R.id.antenatal_Symptom_text);
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view == none) {
                    if (none.isChecked() && cb != view) {
                        cb.setChecked(false);
                        otherText.setText("");
                        otherText.setEnabled(false);
                    }
                } else {
                    CheckBox v = (CheckBox) view;
                    if (v.isChecked()) {
                        none.setChecked(false);
                    }
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
            otherText.setFocusable(true);
            otherText.setFocusableInTouchMode(true);
            otherText.requestFocus();
        } else {
            otherText.setEnabled(false);
            otherText.setText("");
        }
    }

    /**
     * 妇科检查/外阴
     */
    public void changeFukejiancha_waiyinEnableEdit(View view) {
        EditText ed = findViewById(R.id.antenatal_fukejiancha_waiyin_other_text);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.antenatal_fukejiancha_waiyin_noyichang) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
            ed.setFocusable(true);
            ed.setFocusableInTouchMode(true);
            ed.requestFocus();
        }
    }
    /*阴道*/
    public void changefukejiancha_yindaoEnableEdit(View view) {
        EditText ed = findViewById(R.id.antenatal_fukejiancha_yindao_other_txt);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.antenatal_fukejiancha_yindao_noyichang) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
            ed.setFocusable(true);
            ed.setFocusableInTouchMode(true);
            ed.requestFocus();
        }
    }
    /*宫颈*/
    public void changegongjingEnableEdit(View view) {
        EditText ed = findViewById(R.id.antenatal_gongjingyichang2);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.antenatal_gongjingyichang) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
            ed.setFocusable(true);
            ed.setFocusableInTouchMode(true);
            ed.requestFocus();
        }
    }
    /*子宫*/
    public void changeZigongEnableEdit(View view) {
        EditText ed = findViewById(R.id.antenatal_zigongyichangother);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.antenatal_zigongyichang) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
            ed.setFocusable(true);
            ed.setFocusableInTouchMode(true);
            ed.requestFocus();
        }
    }
    /*附件*/
    public void changeFujianEnableEdit(View view) {
        EditText ed = findViewById(R.id.antenatal_fujianyichangother);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.antenatal_fujian) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
            ed.setFocusable(true);
            ed.setFocusableInTouchMode(true);
            ed.requestFocus();
        }
    }
    /*心脏*/
    public void changexinzangEnableEdit(View view) {
        EditText ed = findViewById(R.id.antenatal_xzycother);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.antenatal_xzwyc) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
            ed.setFocusable(true);
            ed.setFocusableInTouchMode(true);
            ed.requestFocus();
        }
    }
    /*末次月经*/
    public void onLast_menstrual_periodClick(View view) {
        TextView tv = findViewById(R.id.antenatal_expecteddateofchildbirth_1);
        CheckBox rb = (CheckBox) view;
        if ((rb.isChecked())==true) {
            tv.setText("");
            tv.setEnabled(false);
        } else if ((rb.isChecked())!=true) {
            tv.setEnabled(true);
        }
    }
    /*肺部*/
    public void changeFeibuEnableEdit(View view) {
        EditText ed = findViewById(R.id.antenatal_fbycother);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.antenatal_fbwyc) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
            ed.setFocusable(true);
            ed.setFocusableInTouchMode(true);
            ed.requestFocus();
        }
    }
    /*手术史*/
    public void changeshoushushiEnableEdit(View view) {
        EditText ed = findViewById(R.id.antenatal_fuchankeshoushushi_other);
        RadioButton rb = (RadioButton) view;
        if (view.getId() == R.id.antenatal_HistoryfoGynecological) {
            ed.setText("");
            ed.setEnabled(false);
        } else if (rb.isChecked()) {
            ed.setEnabled(true);
            ed.setFocusable(true);
            ed.setFocusableInTouchMode(true);
            ed.requestFocus();
        }
    }
    /*
    辅助检查3   阴道分泌物
     */
    public void quxiao(View view) {
        View[] views = getViews(findViewById(R.id.antenatal_fenmiwu));
        CheckBox none = findViewById(R.id.antenatal_cb_1);
        CheckBox other = findViewById(R.id.antenatal_cb_5);
        EditText otherText = findViewById(R.id.antenatal_pay_other_text);
        boolean flag = false;
        for (int i = 0; i < views.length; i++) {
            if (views[i] instanceof CheckBox) {
                CheckBox cb = (CheckBox) views[i];
                if (cb.isChecked()) {
                    flag = true;
                }
                if (view == none) {
                    if (none.isChecked() && cb != view) {
                        cb.setChecked(false);
                        otherText.setText("");
                        otherText.setEnabled(false);
                    }
                } else {
                    CheckBox v = (CheckBox) view;
                    if (v.isChecked()) {
                        none.setChecked(false);
                    }
                }
            }
        }
        if (flag != true) {
            none.setChecked(true);
        }
        if (other.isChecked()) {
            otherText.setEnabled(true);
            otherText.setFocusable(true);
            otherText.setFocusableInTouchMode(true);
            otherText.requestFocus();
        } else {
            otherText.setEnabled(false);
            otherText.setText("");
        }
    }




    /**
     * 获取子视图
     */
    private View[] views;

    private View[] getViews(View view) {
        views = new View[0];
        parseView(view);
        return views;
    }

    private void parseView(View view) {
        if (view instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) view;
            for (int i = 0; i < vg.getChildCount(); i++) {
                View v = vg.getChildAt(i);
                parseView(v);
            }
        } else {
            views = Arrays.copyOf(views, views.length + 1);
            views[views.length - 1] = view;
        }
    }


    /**
     * 提交数据
     */
    public void onClickSubmit(View view) {
        showLoading();
        int count = expandableListView.getExpandableListAdapter().getGroupCount();
        for (int i = 0; i < count; i++) {
            expandableListView.collapseGroup(i);
        }
        Observable.create(new ObservableOnSubscribe<DataBean>() {
            @Override
            public void subscribe(ObservableEmitter<DataBean> emitter) throws Exception {
                JSONObject jsonObject = new JSONObject(mValues);
                MyLogger.i(jsonObject.toString());
                String json = OkgoNetwork.post(url,jsonObject.toString());
                MyLogger.i(json);
                Gson gson = new Gson();
                emitter.onNext(gson.fromJson(json, DataBean.class));

            }
        }).compose(RxUtils.io_main()).subscribe(new ObserverOnNext<DataBean>() {
            @Override
            public void onNext(DataBean dataBean) {
                if (dataBean.getCode()==0){
                    MyToast.show("提交成功");
                    finish();
                }else {
                    MyToast.show(dataBean.getMsg());
                }
                dismissLoading();

            }
        });

    }

    private HubbyBean mBean;
    //新
    private Map<Object,Object> mValues = new HashMap<>();
    private  String url = Constant.baseurl+"online/zxdaycf/save";
    private LoadingViewDialog mLoadingView;
    //整合专项  基础 修改
    private void initBasic(){
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        Toolbar toolbar = (Toolbar)findViewById(com.oracle.children.R.id.toolbar);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        mValues.put("token", User.getToken());
        mValues.put("jmId",getIntent().getIntExtra("jmid", 0) );
        mValues.put("userId", User.getUserId());//社区医生id;
        mValues.put("mark", 1);
        //随访id
        int id = getIntent().getIntExtra("id", 0);
        if (id !=0){
            mValues.put("sfjlId", id);
            mValues.put("id", id);
        }
        //获取丈夫信息
        getParents();
    }

    private void getParents(){
        Observable.create(new ObservableOnSubscribe<HubbyBean>() {
            @Override
            public void subscribe(ObservableEmitter<HubbyBean> emitter) throws Exception {
                Map<Object, Object> values = new HashMap<>();
                values.put("grjbxxId",getIntent().getIntExtra("jmid", 0));
                values.put("mark", 1);
                values.put("token", User.getToken());
                JSONObject jsonObject = new JSONObject(values);
                MyLogger.i(jsonObject.toString()); //获取丈夫信息
                String json = OkgoNetwork.post(Constant.baseurl+"online/zxdaycf/checkZf",jsonObject.toString());
                MyLogger.i(json);
                Gson gson = new Gson();
                emitter.onNext(gson.fromJson(json, HubbyBean.class));
            }
        }).compose(RxUtils.io_main()).subscribe(new ObserverOnNext<HubbyBean>() {
            @Override
            public void onNext(HubbyBean parentsBean) {
                if (parentsBean.getData()!= null){
                    mBean = parentsBean;
                    View[] views = ((CJArchivesExtendableListAdapter) expandableListView.getExpandableListAdapter()).getConvertViews();
                    View view = views[0];
                    if (mBean != null && mBean.getData()!=null){
                        ((EditText) view.findViewById(R.id.antenatal_husbandname)).setText(mBean.getData().getZfxm());
                        ((EditText) view.findViewById(R.id.antenatal_husbandage)).setText(mBean.getData().getZfnl()+"");
                        ((EditText) view.findViewById(R.id.antenatal_husbandphone)).setText(mBean.getData().getZfdh());
                    }

                }

            }
        });

    }



    public void showLoading(){
        mLoadingView = new LoadingViewDialog();
        mLoadingView.show(getSupportFragmentManager(),"" );
    }
    public void dismissLoading(){
        if (mLoadingView != null){
            mLoadingView.dismiss();
        }

    }





}
